import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'



/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
	{
		path: '/login',
		component: () => import('@/views/login/index'),
		hidden: true
	},

	{
		path: '/404',
		component: () => import('@/views/404'),
		hidden: true
	},

	{
		path: '/403',
		component: () => import('@/views/403'),
		hidden: true
	},
	// 左上角标题
	{
		path: '/',
		component: Layout,
		redirect: '/dash_board',
		children: [{
			path: 'dash_board',
			name: '秒秒测管理系统',
			component: () => import('@/views/dashboard/index'),
			meta: { title: '秒秒测管理系统', icon: 'lab' }
		}]
	},
	// 这里直接定义路由
	{
		path: '/dashboard',
		component: Layout,
		name: 'Dashboard',
		meta: { title: '总览', icon: 'user' },
		children: [
			{
				path: 'homepage',
				name: 'Homepage',
				component: () => import('@/views/user/user'),
				meta: { title: '总览', icon: 'table' }
			},
			{
				path: 'monitoring',
				name: 'Monitoring',
				component: () => import('@/views/user/add_user'),
				meta: { title: '实时监控', icon: 'table' }
			},
		]
	},
	{
		path: '/User',
		component: Layout,
		// redirect: '/user/table',
		name: 'User',
		meta: { title: '用户', icon: 'user' },
		children: [
			{
				path: 'table',
				name: 'Table',
				component: () => import('@/views/user/user'),
				meta: { title: '用户信息', icon: 'table' }
			},
			{
				path: 'add_user',
				name: 'AddUser',
				component: () => import('@/views/user/add_user'),
				meta: { title: '添加用户', icon: 'table' }
			},
			{
				path: 'company',
				name: 'Company',
				component: () => import('@/views/user/company'),
				meta: { title: '公司信息', icon: 'tree' }
			},
			{
				path: 'character',
				name: 'Character',
				component: () => import('@/views/user/character'),
				meta: { title: '角色管理', icon: 'tree' }
			},
			{
				path: 'right',
				name: 'Right',
				component: () => import('@/views/user/right'),
				meta: { title: '权限管理', icon: 'tree' }
			},
			{
				path: 'history',
				name: 'History',
				component: () => import('@/views/tree/index'),
				meta: { title: '操作记录', icon: 'tree' }
			},
		]
	},
	{
		path: '/deal',
		component: Layout,
		name: 'Deal',
		meta: { title: '交易', icon: 'user' },
		children: [
			{
				path: 'add_custom',
				name: 'AddCustom',
				component: () => import('@/views/deal/add_custom'),
				meta: { title: '添加客户', icon: 'table' }
			},
			{
				path: 'send',
				name: 'Send',
				component: () => import('@/views/deal/send'),
				meta: { title: '创建标签', icon: 'table' }
			},
			{
				path: 'receive',
				name: 'Receive',
				component: () => import('@/views/deal/receive'),
				meta: { title: '收货中心', icon: 'table' }
			},
		]
	},
	{
		path: '/order',
		component: Layout,
		name: 'Order',
		meta: { title: '标签', icon: 'user' },
		children: [
			{
				path: 'order_info',
				name: 'OrderInfo',
				component: () => import('@/views/order/order_info'),
				meta: { title: '标签列表', icon: 'table' }
			},
			{
				path: 'custom_info',
				name: 'CustomInfo',
				component: () => import('@/views/order/custom_info'),
				meta: { title: '客户列表', icon: 'table' }
			},
		]
	},
	{
		path: '/type',
		component: Layout,
		name: 'Type',
		meta: { title: '货物', icon: 'user' },
		children: [
			{
				path: 'type_info',
				name: 'TypeInfo',
				component: () => import('@/views/type/type_info'),
				meta: { title: '货物类型', icon: 'table' }
			},
			{
				path: 'add_type',
				name: 'AddType',
				component: () => import('@/views/type/add_type'),
				meta: { title: '添加货物类型', icon: 'table' }
			},
		]
	},
	{
		path: '/analysis',
		component: Layout,
		name: 'Analysis',
		meta: { title: '分析', icon: 'user' },
		children: [
			{
				path: 'order_analysis',
				name: 'OrderAnalysis',
				component: () => import('@/views/analysis/order_analysis'),
				meta: { title: '物流路线分析', icon: 'table' }
			},
			{
				path: 'chart',
				name: 'Chart',
				component: () => import('@/views/analysis/chart'),
				meta: { title: '路线分析', icon: 'table' }
			},
		]
	},

	{
		path: 'external-link',
		component: Layout,
		children: [
			{
				path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
				meta: { title: 'External Link', icon: 'link' }
			}
		]
	},

	// 404 page must be placed at the end !!!
	{ path: '*', redirect: '/404', hidden: true },

]

const createRouter = () => new Router({
	mode: 'history', // require service support
	scrollBehavior: () => ({ y: 0 }),
	routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
	const newRouter = createRouter()
	router.matcher = newRouter.matcher // reset router
}

export default router
